#ifndef DEBUGHELPER_H
#define DEBUGHELPER_H

#ifndef QT_NO_DEBUG
#include <QDebug>
#endif

// fatalError() is a convenience function for terminating the program and writing out a formatted message
// it works with any variable or object that can be printed out
//
// for instance, calling it with fatalError(orientation), where orientation is int with value 99, will print out:
// "ASSERT: "Invalid value of orientation: 99, in function
//  void HierarchicalStandardItemModel::setSection(int, const QString&, Qt::Orientation)."
//  in file ..\final-mark\src\hierarchical-standard-item-model.cpp, line 117"
//
// additionally, Qt Creator turns the location of the error into a clickable hyperlink,
// which leads to a proper file and line of code

#if !defined(fatalError)
#  ifndef QT_NO_DEBUG
#    define fatalError(variable) qFatal("ASSERT: \"%s\" in file %s, line %d", \
                                        QString("Invalid value of %1: %2, in function %3.") \
                                        .arg(#variable).arg(variable).arg(Q_FUNC_INFO).toUtf8().constData(), \
                                        __FILE__, __LINE__)
#  else
#    define fatalError(variable) qt_noop()
#  endif
#endif

#ifndef qdebug
    #ifndef QT_NO_DEBUG
        #define qdebug(text) qDebug() << text
    #else
        #define qdebug(text) qt_noop()
    #endif
#endif

#endif // DEBUGHELPER_H
